package com.hw.one.collect.dust.util;

import com.hw.one.collect.util.MathCalculateUtil;

/**
 * Created by Administrator on 2017/8/7.
 */
public class WeatherUtil {


    public static String changeAngleToWindDirection(String angle) {
        if (null == angle || "".equals(angle) || "null".equals(angle)) {
            return "-";
        }

        // 如果传入的不是数字，则返回传入的参数值
        if (!MathCalculateUtil.isNumeric(angle)) {
            return angle;
        }

        // 转化为数字
        double angle_D = Double.parseDouble(angle);

        if (0 == angle_D) {
            return "N";
        }

        if (90 == angle_D) {
            return "E";
        }

        if (180 == angle_D) {
            return "S";
        }

        if (270 == angle_D) {
            return "W";
        }

        if (angle_D > 0 && angle_D < 90) {
            return "NE";
        }

        if (angle_D > 90 && angle_D < 180) {
            return "SE";
        }

        if (angle_D > 180 && angle_D < 270) {
            return "SW";
        }

        if (angle_D > 270 && angle_D < 360) {
            return "NW";
        }

        return "";
    }


    public static String changeWDWithEng(String angle_D) {
        if (null == angle_D || "".equals(angle_D) || "null".equals(angle_D)) {
            return "";
        }

        if ("N".equalsIgnoreCase(angle_D)) {
            return "N";
        }

        if ("E".equalsIgnoreCase(angle_D)) {
            return "E";
        }

        if ("S".equalsIgnoreCase(angle_D)) {
            return "S";
        }

        if ("W".equalsIgnoreCase(angle_D)) {
            return "W";
        }

        if ("NE".equalsIgnoreCase(angle_D) || "EN".equalsIgnoreCase(angle_D)) {
            return "NE";
        }
        if ("SE".equalsIgnoreCase(angle_D) || "ES".equalsIgnoreCase(angle_D)) {
            return "SE";
        }

        if ("SW".equalsIgnoreCase(angle_D) || "WS".equalsIgnoreCase(angle_D)) {
            return "SW";
        }

        if ("NW".equalsIgnoreCase(angle_D) || "WN".equalsIgnoreCase(angle_D)) {
            return "NW";
        }
        if ("ESWN".equalsIgnoreCase(angle_D)) {
            return "ESWN";
        }
        return angle_D;

    }


    public static String dealWD(String wd) {
        wd = changeAngleToWindDirection(wd);
        wd = changeWDWithEng(wd);
        return wd;
    }

    public static void main(String[] args) {
        String s1 = "123.54";
        String s2 = "wN";
        String s3 = "ESWN";
        String s4 = "w";
        String s5 = "SE";
        String s6 = "SW";
        String ds1 = dealWD(s1);
        String ds2 = dealWD(s2);
        String ds3 = dealWD(s3);
        String ds4 = dealWD(s4);
        String ds5 = dealWD(s5);
        String ds6 = dealWD(s6);
        System.out.println(s1 + " = " + ds1);
        System.out.println(s2 + " = " + ds2);
        System.out.println(s3 + " = " + ds3);
        System.out.println(s4 + " = " + ds4);
        System.out.println(s5 + " = " + ds5);
        System.out.println(s6 + " = " + ds6);
    }


}
